<?php

namespace App\Service\Message\v1_2_1;

use App\Cache\UserRemarkCache;
use App\Constants\ErrorCode;
use App\Model\CloseFriend;
use App\Model\User;
use App\Model\UserProfile;
use App\Service\User\UserBaseService;
use App\Model\UserBlacklist;
/**
 * 密友列表
 */
class CloseFriendService extends UserBaseService
{
    //单向聊天限制
    protected $msgLmt = 3;

    protected function RoVerifyList()
    {
        return [
            'page' => 'required|int'
        ];
    }

    public function handle()
    {
        $ret = ['list' => []];
        $page = $this->request->input('page', 1);
        $userIds = CloseFriend::getFrdList($this->userId);

        //获取已经注销用户
        $logoutUids = User::getLogout($userIds);
        //获取拉黑用户
        $UserBlackUids = UserBlacklist::getList('uid');

        //排除注销和拉黑用户
        $userIds = array_values(array_diff($userIds, $logoutUids,$UserBlackUids));

        $start = ($page - 1) * $this->pageNum;
        $userIds = array_slice($userIds, $start, $this->pageNum);

        $usersInfo = UserProfile::getUsersProfile($userIds, false, true);
        $imAccounts = User::getImAccounts($userIds, -1);
        $selfProfile = UserProfile::getProfile($this->userId);
        
        foreach ($usersInfo as $info) {
            $item = $this->buildUserItem($info, $this->userId);
//            if ($selfProfile->gender == 1) $item['online_time'] = '';
            $item['im_account'] = $imAccounts[$info['user_id']];
            $item['remark'] = $this->userId != $info['user_id'] ? (new UserRemarkCache())->getRemark($this->userId, $info['user_id']) : '';

            $ret['list'][] = $item;
        }
        return $ret;
    }
}
